package com.aimee.mvp.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.aimee.mvp.bean.Account;
import com.aimee.mvp.view.IMVPView;
import com.aimee.mvp.presenter.MVPPresenter;
import com.aimee.mvp.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MVPActivity extends AppCompatActivity implements IMVPView {

    @BindView(R.id.et_account)
    EditText etAccount;
    @BindView(R.id.btn_search)
    Button btnSearch;
    @BindView(R.id.tv_result)
    TextView tvResult;

    private MVPPresenter mMVPPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvp);
        ButterKnife.bind(this);

        mMVPPresenter = new MVPPresenter(this);
    }

    @OnClick(R.id.btn_search)
    public void onViewClicked() {
        mMVPPresenter.getData(getUserInput());
    }

    @Override
    public String getUserInput() {
        return etAccount.getText().toString();
    }

    @Override
    public void showSuccessPage(Account account) {
        tvResult.setText(String.format(getResources().getString(R.string.str_result_name_and_level),
                account.getName(), account.getLevel()));
    }

    @Override
    public void showFailPage() {
        tvResult.setText(R.string.str_get_data_fail);
    }
}
